/*
moxl - Modular XML Library
Copyright (c) 2007, Malcolm Sparks

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/
package moxl.xpath.parser.parser;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import moxl.reader.LocateableReader;
import moxl.reader.XPathExpressionReader;
import moxl.tokenizer.TokenStream;
import moxl.tokenizer.Tokenizer;
import moxl.tokenizer.WhitespaceFilteringTokenStream;
import moxl.xpath.parser.XPathParser;
import moxl.xpath.parser.types.Expression;
import moxl.xpath.parser.types.FunctionCall;
import moxl.xpath.parser.types.PathExpression;
import moxl.xpath.parser.types.XPathLiteralOperand;
import moxl.xpath.parser.types.XPathNumberOperand;
import moxl.xpath.tokenizer.StartState;

import org.junit.Before;
import org.junit.Test;

public class FunctionCallParserTest1
{
	private XPathParser parser;
	private TokenStream tstream;
	private FunctionCall fnCall;

	@Before
	public void setUp() throws Exception
	{
		LocateableReader reader = new XPathExpressionReader("foo(123, 'alice', child::foo, (2+3), bar(1,2))");
		Tokenizer toker = new Tokenizer(reader, StartState.getInstance());
		tstream = new WhitespaceFilteringTokenStream(toker);
		parser = new XPathParser();
		fnCall = parser.parseFunctionCallFromStream(tstream);
	}

	@Test
	public void functionCallNotNull()
	{
		assertNotNull(fnCall);
	}

	@Test
	public void functionName()
	{
		assertEquals("foo", fnCall.getFunctionName());
	}

	@Test
	public void functionArgumentsNumber()
	{
		assertEquals(5, fnCall.getArguments().length);
	}

	@Test
	public void firstArgumentType()
	{
		assertEquals(XPathNumberOperand.class, fnCall.getArguments()[0].getClass());
	}

	@Test
	public void secondArgumentType()
	{
		assertEquals(XPathLiteralOperand.class, fnCall.getArguments()[1].getClass());
	}

	@Test
	public void thirdArgumentType()
	{
		assertEquals(PathExpression.class, fnCall.getArguments()[2].getClass());
	}

	@Test
	public void fourthArgumentType()
	{
		assertEquals(Expression.class, fnCall.getArguments()[3].getClass());
	}

	@Test
	public void fifthArgumentType()
	{
		assertEquals(FunctionCall.class, fnCall.getArguments()[4].getClass());
	}
}
